package com.UI;

import com.Model.StudentDBModel;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;

public class HomePageold extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.home_page);

		Button btnviewCourses = (Button) findViewById(R.id.btnviewCourses);
		btnviewCourses.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View component) {

				Intent viewCourses = new Intent();
				viewCourses.setClassName("com.UI", "com.UI.CourseList");
				startActivity(viewCourses);
			}
		});

		Button btnSchedule = (Button) findViewById(R.id.btnSchedule);
		btnSchedule.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View component) {

				Intent schedule = new Intent();
				schedule.setClassName("com.UI", "com.UI.Schedule");
				startActivity(schedule);
			}
		});

		Button btnToDo = (Button) findViewById(R.id.btnToDo);
		btnToDo.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View component) {

				Intent viewtodo = new Intent();
				viewtodo.setClassName("com.UI", "com.UI.ToDoList");
				startActivity(viewtodo);
			}
		});

		/**
		 * This button will allow the user to enter the web address of their
		 * University's student webmail page. Once a webmail address is entered,
		 * clicking this button will open the webmail address in a browser
		 * window
		 */
		Button btnviewWebmail = (Button) findViewById(R.id.btnviewWebmail);
		btnviewWebmail.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View component) {
				// create a model instance
				StudentDBModel newWebmail = new StudentDBModel(HomePageold.this);

				int numWebmails = newWebmail.getNumWebmails();
				// find out if a webmail has already been entered
				if (numWebmails > 0) {
					// a webmail has already been entered, so open it in the
					// browser
					Intent webmailGo = new Intent(HomePageold.this,
							GoToStudentWebmail.class);
					startActivity(webmailGo);
				} else {
					// no webmail has been entered, so show the entry form
					Intent webmailAdd = new Intent(HomePageold.this,
							AddStudentWebmail.class);
					startActivity(webmailAdd);
				}
			}
		});

		/*
		 * If the user wants to view the Grades. The following button click will
		 * take him/her to the Grades page
		 */
		Button btnviewGrades = (Button) findViewById(R.id.btnviewGrades);
		btnviewGrades.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View component) {

				Intent viewGrades = new Intent();
				viewGrades.setClassName("com.UI", "com.UI.Grades");
				startActivity(viewGrades);
			}
		});

		/*
		 * If the user wants to view Extra Curricular Activities. The following
		 * button click will take him/her to the Curricular page
		 */
		Button btnviewCurricular = (Button) findViewById(R.id.btnviewCurricular);
		btnviewCurricular.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View component) {

				Intent viewCurricular = new Intent();
				viewCurricular.setClassName("com.UI", "com.UI.ExtraCurricular");
				startActivity(viewCurricular);
			}
		});

		Button btnGoogle = (Button) findViewById(R.id.btnGoogle);
		btnGoogle.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View component) {

				Intent viewgoogle = new Intent();
				viewgoogle.setClassName("com.UI", "com.UI.GoogleSearch");
				startActivity(viewgoogle);
			}
		});

	}

	/*
	 * If the user wants to view the preferences. The following menu button
	 * click will take him/her to the preferences page
	 */

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.add_menu, menu);
		return true;
	}

	// for the menu. If you want to add more items to it, just add them to the
	// switch case and you are all done.
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {

		case R.id.preferences:
			Intent viewPreferences = new Intent();
			viewPreferences.setClassName("com.UI", "com.UI.Preferences");
			startActivity(viewPreferences);
			break;

		}
		return true;
	}

}
